/*
 * Copyright 2010-2011 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package kr.co.cooknote.config;

import javax.sql.DataSource;

import org.apache.ibatis.session.SqlSessionFactory;
//import org.h2.jdbcx.JdbcConnectionPool;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import com.springsource.greenhouse.database.DatabaseUpgrader;
//import org.springframework.jdbc.versioned.DatabaseChangeSet;
//import org.springframework.jdbc.versioned.SqlDatabaseChange;
//import org.springframework.jdbc.versioned.DatabaseChangeSet;
//import org.springframework.jdbc.versioned.SqlDatabaseChange;

//import com.springsource.greenhouse.database.DatabaseUpgrader;



@Configuration
@MapperScan("kr.co.cooknote")
public class MyBatisConfig {

    @Autowired
    DataSource dataSource;

    @Bean
    public SqlSessionFactory sqlSessionFactory() throws Exception {

        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
        sessionFactory.setDataSource(dataSource);
//      sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:kr.co.cooknote.dashboard.mapper"));
        sessionFactory.setTypeAliasesPackage("kr.co.cooknote.dashboard");
        sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources("classpath:kr/co/cooknote/sqlmapper/**/*.xml"));

        //http://theeye.pe.kr/archives/1487
        //http://blog.naver.com/smrdev/220085942175
        //http://jeremyko.blogspot.kr/2012/07/mybatis-spring.html
        //http://jeremyko.blogspot.kr/2012/07/mybatis-spring.html

        return sessionFactory.getObject();
    }

//
//	@Bean
//	public PlatformTransactionManager annotationDrivenTransactionManager() {
//		return new DataSourceTransactionManager(dataSource);
//	}
//
//	@Bean
//	public SqlSession sqlSessionTemplate() throws Exception {
//		return new SqlSessionTemplate(sqlSessionFactory());
//	}


}

